from functools import lru_cache
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    # Database
    database_url: str = Field(default="sqlite:///./ai_server_monitor.db", env="DATABASE_URL")

    # Security key for encrypting credentials at rest (Fernet key)
    secret_key: str = Field(default="change-me-in-.env", env="SECRET_KEY")

    # SSH defaults
    ssh_timeout_seconds: int = Field(default=10, env="SSH_TIMEOUT_SECONDS")

    # pydantic-settings v2 配置
    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")


@lru_cache()
def get_settings() -> Settings:
    return Settings()

